package Change.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Entity
@Table(name="change_interest")
public class Interest extends BaseObject implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Long id;
	private String name;
	private Interest parent;
	private Set<Interest> subInterests = new HashSet<Interest>();
	
	

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	/**
	 * 兴趣爱好的上级 如,篮球的上级为运动
	 * @return 当前兴趣爱好的上级
	 */
	@ManyToOne
	public Interest getParent() {
		return parent;
	}

	/**
	 * 自己目录的子级,如运动的子级有篮球,足球
	 * @return 当前兴趣爱好的子级
	 */
	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE },
			mappedBy="parent")
	public Set<Interest> getSubInterests() {
		return subInterests;
	}

	public void setSubInterests(Set<Interest> subInterests) {
		this.subInterests = subInterests;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setParent(Interest parent) {
		this.parent = parent;
	}

	@Override
	public boolean equals(Object o) {
		if(this == o)
			return true;
		if((o instanceof Interest))
			return true;
		else 
			return false;
	}

	@Override
	public int hashCode() {
		return (name != null ? name.hashCode() : 0);
	}

	@Override
	public String toString() {
		return(new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
				.append("name",this.name)
				.append("parene",this.parent)).toString();
				
	}

}
